package com.dragon.mapper;

import com.dragon.pojo.User.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("SELECT id, username, password, permissions,email, nickname, bio, avatar, create_time, update_time from user where username = #{identifier} and password = #{password}")
    User loginForUserName(LoginInfo loginInfo);

    @Select("SELECT id, username, password, permissions,email, nickname, bio, avatar, create_time, update_time from user where email = #{identifier} and password = #{password}")
    User loginForEmail(LoginInfo loginInfo);

    @Insert("INSERT INTO user (username,password,email,nickname,permissions,create_time,update_time) values (#{username},#{password},#{email},#{username},'user',#{createTime},#{updateTime})")
    void register(User user);

    @Select("SELECT id, username, password, email, nickname, bio, avatar, permissions, is_code_public, create_time, update_time from user where id = #{id}")
    UserInfo getUserInfo(User user);

    @Update("UPDATE user SET email=#{email}, nickname=#{nickname}, bio=#{bio}, is_code_public=#{isCodePublic}, update_time=now() where id=#{id}")
    void updateUserInfo(User user);

    @Select("SELECT password from user where id = #{id}")
    String getPasswordForId(User user);

    @Update("UPDATE user SET password=#{password},update_time=now() where id=#{id}")
    void updatePassword(User user);

    @Delete("DELETE FROM user where id=#{id} and password=#{password}")
    void logout(User user);

    @Update("UPDATE user SET avatar=#{avatar}, update_time=now() where id=#{id}")
    void updateAvatar(User user);

    @Select("SELECT avatar from user where id=#{id}")
    User getAvatarById(User user);

    List<UserList> getUserList(UserSelectInfo info);

    Integer getUserTotal(UserSelectInfo info);

    @Select("SELECT username FROM user where id=#{userId}")
    String getUsername(Integer userId);

    @Select("SELECT is_code_public from user where id=#{userId}")
    int getUserCodePublic(Integer userId);
}
